﻿using Day13.Domain;
using Day13.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Day13.IService
{
    public class IDataService
    {
        IDataRepository<Datas> DatasRep;

        public IDataService(IDataRepository<Datas> datasRep)
        {
            DatasRep = datasRep;
        }

        public dynamic Show(string? DatasNo, string? Name)
        {
            var list = from a in DatasRep.GetAll()
                       select new
                       {
                           a.DatasId,
                           a.DatasName,
                           a.YwName,
                           a.DatasNo,
                           a.LcNo,
                           a.Name,
                           a.Rw,
                           a.BlName,
                           a.strstTime,
                           DataTimes = DateTime.Now - a.strstTime,
                           a.IsDel
                       };
            if (!string.IsNullOrEmpty(DatasNo))
            {
                list = list.Where(x => x.DatasNo.Contains(DatasNo));
            }
            if (!string.IsNullOrEmpty(Name))
            {
                list = list.Where(x => x.Name.Contains(Name));
            }
            return list;
        }
    }
}
